/**
 * Copyright (C) 2010, 2011 Neofonie GmbH
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.dicode.analysis.demonstrator.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * Provides the web frontend with all known queries that have been tracked by us.
 *
 * Implementation is not thread safe. Can be used in a threaded context only if
 * initialized at the very beginning and re-used but left stable there-after.
 * Concurrent modification and usage not recommended.
 */
public class HomeCommand {
  private final Collection<String> allKnownHistograms;
  private final Collection<String> allKnownCollocations;

  private volatile String selectedHist;
  private volatile String selectedColloc;

  public HomeCommand() {
    this.allKnownHistograms = new ArrayList<String>();
    this.allKnownCollocations = new ArrayList<String>();
  }

  /**
   * Returns a safe copy of the collection of all query strings known to the system.
   * Modification of the returned collection does NOT lead to modification of the
   * internal state of this object.
   * */
  public Collection<String> getAllKnownHistograms() {
    return Collections.unmodifiableCollection(this.allKnownHistograms);
  }

  /**
   * Resets the internal collection of all known queries to the content passed in
   * as parameter. For safety reasons call this method only for initialization and
   * leave it alone thereafter if multiple threads are using this command.
   * */
  public void setAllKnownHistograms(final Collection<String> allKnownQueries) {
    this.allKnownHistograms.clear();
    this.allKnownHistograms.addAll(allKnownQueries);
  }

  public Collection<String> getAllKnownCollocations() {
    return Collections.unmodifiableCollection(this.allKnownCollocations);
  }

  public void setAllKnownCollocations(final Collection<String> allKnownQueries) {
    this.allKnownCollocations.clear();
    this.allKnownCollocations.addAll(allKnownQueries);
  }

  public String getSelectedHist() {
    return this.selectedHist;
  }

  public void setSelectedHist(final String selectedQuery) {
    this.selectedHist = selectedQuery;
  }

  public String getSelectedColloc() {
    return this.selectedColloc;
  }

  public void setSelectedColloc(final String selectedQuery) {
    this.selectedColloc = selectedQuery;
  }
}
